/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavadata.query;

import edu.pdx.cs.guavadata.Transaction;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author VuTran
 */
public class Command {
    public Operator root;
    public Transaction container;
    private Map<String, String> tableAliases;
    private int tableCount;
    private int loopCount;

    public Command() {
        tableAliases = new HashMap<String, String>();
        tableCount = 0;
        container = null;
    }


    public Command(Operator o) {
        this();
        root = o;
    }

    public Command cloneState(Operator o) {
        Command c = new Command(o);
        c.tableCount = this.tableCount;
        for (String key : tableAliases.keySet())
            c.tableAliases.put(key, tableAliases.get(key));
        return c;
    }

    public String nextTableAlias(String table) {
        // create the new alias and increment
        String newAlias = "T_" + tableCount;
        tableCount++;

        // Add the alias to the table and return the alias
        tableAliases.put(newAlias, table);
        return newAlias;
    }

    public String getNextLoopAlias() {
        String retVal = "t" + tableCount;
        tableCount++;
        return retVal;
    }

    public void notifyChange(Command...onew) {
        this.container.notifyChange(this, onew);
    }
}
